package com.chb.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chb.system.mapper.RegisteredItemMapper;
import com.chb.system.service.RegisteredItemService;
import com.chb.system.vo.RegisteredItemVo;
import com.hos.entity.sys.RegisteredItem;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author ：张家琪
 * @date ：Created in 2023/12/12 15:48
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class RegisteredItemServerImpl implements RegisteredItemService {
    @Resource
    private RegisteredItemMapper registeredItemMapper;

    /**
     * 查询所有挂号信息列表
     */
    @Override
    public List<RegisteredItem> getRegisteredItemAll() {
        LambdaQueryWrapper<RegisteredItem> wrapper = new LambdaQueryWrapper<>();
        // wrapper.eq(RegisteredItem::getStatus, "0");
        return registeredItemMapper.selectList(wrapper);
    }

    // 条件查询挂号项目费用
    @Override
    public Page<RegisteredItem> findRegisteredItemByCond(RegisteredItemVo registeredItemVo) {
        Page<RegisteredItem> page = new Page<>(registeredItemVo.getPageNum(), registeredItemVo.getPageSize());
        LambdaQueryWrapper<RegisteredItem> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(registeredItemVo.getRegItemName())) {
            wrapper.like(RegisteredItem::getRegItemName, registeredItemVo.getRegItemName());
        }
        if (StringUtils.hasText(registeredItemVo.getStatus())) {
            wrapper.eq(RegisteredItem::getStatus, registeredItemVo.getStatus());
        }
        return registeredItemMapper.selectPage(page, wrapper);

    }

    @Override
    public Integer addRegisteredItem(RegisteredItem registeredItem) {
        // 创建时间
        registeredItem.setCreateTime(new Date());
        return registeredItemMapper.insert(registeredItem);
    }

    @Override
    public Integer deleteRegisteredItemByIds(List<Long> ids) {
        return registeredItemMapper.deleteBatchIds(ids);
    }

    @Override
    public RegisteredItem getRegisteredItemById(Long registeredItemId) {
        return registeredItemMapper.selectById(registeredItemId);
    }

    @Override
    public Integer updateRegisteredItem(RegisteredItem registeredItem) {
        return registeredItemMapper.updateById(registeredItem);
    }
}